<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<%@ Import Namespace="System.Diagnostics" %>


<html>
<head>
<!--------------------------------------------------------------------------->

<script language="VB" runat=server>

  Sub Page_Load(Source As Object, E As EventArgs) 
    
    Dim myConnection As SQLConnection
    Dim ConnStr      As String
    Dim i            As Integer
    Dim x            As Integer
    Dim y            As Integer

    ' set the connection details
    ConnStr = "Server=localhost; database=_pubs; UID=sa"

    Try
      myConnection = New SQLConnection(ConnStr)
      myConnection.Open()

      i = x / y

    Catch exSQL As SQLException
      WriteToEventLog("Wrox", exSQL.ToString())

    Catch ex As Exception
      WriteToEventLog("Wrox", ex.ToString())


    Finally
      FinishedMessage.Text = "Finished"

    End Try

  End Sub

  Sub WriteToEventLog(LogName As String, Message As String)

    ' Create Event Log if It Doesn't Exist
    If (Not EventLog.SourceExists(LogName)) Then
      EventLog.CreateEventSource(LogName, LogName)
    End if

    ' Fire off to Event Log
    Dim Log as New EventLog
    Log.Source = LogName
    Log.WriteEntry(Message, EventLogEntryType.Error)

  End Sub

</script>

<asp:label id="FinishedMessage" runat="server" />

</html>